﻿#include "mainwindow.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>

MainWindow::MainWindow(QWidget* parent)
    : QMainWindow(parent),  m_dragging(false),stackedWidget(new QStackedWidget),
      page1(new Page1), page2(new Page2), page3(new Page3), page4(new Page4),
      page5(new Page5), page6(new Page6), page7(new Page7), page8(new Page8),
      page9(new Page9), page10(new Page10), page11(new Page11), page12(new Page12),
      page13(new Page13)/*connectionDialog(new ConnectionDialog(this))*/  // 确保这里的成员初始化列表正确
{
    // 设置窗口标志为无边框窗口
        setWindowFlags(Qt::FramelessWindowHint);
        // 设置窗口背景透明
        setAttribute(Qt::WA_TranslucentBackground);

        // 固定窗口大小
        setFixedSize(1280, 750);

        // 创建自定义标题栏
        titleBar = new QWidget(this);
        titleBar->setFixedHeight(40);
        titleBar->setStyleSheet("background-color: #EEEEEE;");

        // 创建图像标签
        QLabel *imageLabel = new QLabel(titleBar);
        QPixmap pixmap(":new/prefix1/ERP.jpg");  // 替换为实际图片路径
        imageLabel->setPixmap(pixmap);
        imageLabel->setFixedSize(40, 40);  // 根据需要调整大小

        // 项目名称标签
        titleLabel = new QLabel("企业资源计划系统", titleBar);
        titleLabel->setStyleSheet("padding-left: 10px; font-size: 20px; font-weight: bold; color: #000000;");
        titleLabel->setFixedHeight(40);


        // 创建按钮
        minimizeButton = new QPushButton("-", titleBar);
        //maximizeButton = new QPushButton("□", titleBar);
        closeButton = new QPushButton("×", titleBar);  // 修改为叉号

        minimizeButton->setFixedSize(40, 40);
        //maximizeButton->setFixedSize(40, 40);
        closeButton->setFixedSize(40, 40);

        // 设置按钮样式
        minimizeButton->setStyleSheet("QPushButton { background-color: #EEEEEE; border: none; } QPushButton:hover { background-color: #CCCCCC; }");
        //maximizeButton->setStyleSheet("QPushButton { background-color: #EEEEEE; border: none; } QPushButton:hover { background-color: #CCCCCC; }");
        closeButton->setStyleSheet("QPushButton { background-color: #EEEEEE; border: none; } QPushButton:hover { background-color: #FF0000; }");

        // 布局按钮到右上角
        QHBoxLayout *buttonLayout = new QHBoxLayout();
        buttonLayout->addStretch();
        buttonLayout->addWidget(minimizeButton);
        //buttonLayout->addWidget(maximizeButton);
        buttonLayout->addWidget(closeButton);
        buttonLayout->setContentsMargins(0, 0, 0, 0);
        buttonLayout->setSpacing(5);

        // 主布局，包含图像、项目名称和按钮
        QHBoxLayout *titleLayout = new QHBoxLayout(titleBar);
        titleLayout->addWidget(imageLabel);  // 添加图像标签
        titleLayout->addWidget(titleLabel);
        titleLayout->addStretch();
        titleLayout->addLayout(buttonLayout);
        titleLayout->setContentsMargins(0, 0, 0, 0);
        titleLayout->setSpacing(5);

        // 连接按钮信号槽
        connect(minimizeButton, &QPushButton::clicked, this, &MainWindow::on_minimizeButton_clicked);
      //  connect(maximizeButton, &QPushButton::clicked, this, &MainWindow::on_maximizeButton_clicked);
        connect(closeButton, &QPushButton::clicked, this, &MainWindow::on_closeButton_clicked);

        // 设置自定义标题栏
        setMenuWidget(titleBar);

        // 创建中央窗口部件
        QWidget *centralWidget = new QWidget(this);
        centralWidget->setGeometry(0, 40, 1280, 720);  // 设置中央窗口部件的位置和大小
        setCentralWidget(centralWidget);

    stackedWidget->addWidget(page1);
    stackedWidget->addWidget(page2);
    stackedWidget->addWidget(page3);
    stackedWidget->addWidget(page4);
    stackedWidget->addWidget(page5);
    stackedWidget->addWidget(page6);
    stackedWidget->addWidget(page7);
    stackedWidget->addWidget(page8);
    stackedWidget->addWidget(page9);
    stackedWidget->addWidget(page10);
    stackedWidget->addWidget(page11);
    stackedWidget->addWidget(page12);
    stackedWidget->addWidget(page13);
    // Add other pages to stacked widget here (page3, page4, ..., page12)

    setCentralWidget(stackedWidget);

    // Connect signals for other pages here (page3, page4, ..., page12)

    stackedWidget->setCurrentWidget(page1); // Start with page1


    connect(page1, &Page1::nextPageRequested, this, &MainWindow::nextPage);

    connect(page2, &Page2::pageRequested6, this, &MainWindow::pageRequested6);
    connect(page2, &Page2::orderRequested, this, &MainWindow::orderRequested);
    connect(page2, &Page2::storeRequested, this, &MainWindow::storeRequested);
    connect(page2, &Page2::productionRequested, this, &MainWindow::productionRequested);
    connect(page2, &Page2::financeRequested, this, &MainWindow::financeRequested);
    connect(page2, &Page2::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page2, &Page2::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page2,&Page2::pageRequested13,this,&MainWindow::pageRequested13);


    connect(page3, &Page3::pageRequested7, this, &MainWindow::pageRequested7);
    connect(page3, &Page3::pageRequested8, this, &MainWindow::pageRequested8);
    connect(page3, &Page3::pageRequested9, this, &MainWindow::pageRequested9);
    connect(page3, &Page3::orderRequested, this, &MainWindow::orderRequested);
    connect(page3, &Page3::storeRequested, this, &MainWindow::storeRequested);
    connect(page3, &Page3::productionRequested, this, &MainWindow::productionRequested);
    connect(page3, &Page3::financeRequested, this, &MainWindow::financeRequested);
    connect(page3, &Page3::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page3, &Page3::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page3,&Page3::pageRequested13,this,&MainWindow::pageRequested13);

    connect(page4, &Page4::orderRequested, this, &MainWindow::orderRequested);
    connect(page4, &Page4::storeRequested, this, &MainWindow::storeRequested);
    connect(page4, &Page4::productionRequested, this, &MainWindow::productionRequested);
    connect(page4, &Page4::financeRequested, this, &MainWindow::financeRequested);
    connect(page4, &Page4::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page4, &Page4::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page4,&Page4::pageRequested13,this,&MainWindow::pageRequested13);
    // connect(page5, &Page5::frontPageRequested, this, &MainWindow::frontPage);
    connect(page5, &Page5::orderRequested, this, &MainWindow::orderRequested);
    connect(page5, &Page5::storeRequested, this, &MainWindow::storeRequested);
    connect(page5, &Page5::productionRequested, this, &MainWindow::productionRequested);
    connect(page5, &Page5::financeRequested, this, &MainWindow::financeRequested);
    connect(page5, &Page5::pageRequested11, this, &MainWindow::pageRequested11);
    connect(page5, &Page5::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page5, &Page5::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page5,&Page5::pageRequested13,this,&MainWindow::pageRequested13);


    connect(page6, &Page6::frontPageRequested, this, &MainWindow::frontPage);
    connect(page6, &Page6::orderRequested, this, &MainWindow::orderRequested);
    connect(page6, &Page6::storeRequested, this, &MainWindow::storeRequested);
    connect(page6, &Page6::productionRequested, this, &MainWindow::productionRequested);
    connect(page6, &Page6::financeRequested, this, &MainWindow::financeRequested);
    connect(page6, &Page6::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page6, &Page6::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page6,&Page6::pageRequested13,this,&MainWindow::pageRequested13);
    // connect(page7, &Page7::frontPageRequested, this, &MainWindow::frontPage);
    connect(page7, &Page7::orderRequested, this, &MainWindow::orderRequested);
    connect(page7, &Page7::storeRequested, this, &MainWindow::storeRequested);
    connect(page7, &Page7::productionRequested, this, &MainWindow::productionRequested);
    connect(page7, &Page7::financeRequested, this, &MainWindow::financeRequested);
    connect(page7, &Page7::pageRequested7, this, &MainWindow::pageRequested7);
    connect(page7, &Page7::pageRequested8, this, &MainWindow::pageRequested8);
    connect(page7, &Page7::pageRequested9, this, &MainWindow::pageRequested9);
    connect(page7, &Page7::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page7, &Page7::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page7,&Page7::pageRequested13,this,&MainWindow::pageRequested13);


    // connect(page8, &Page8::frontPageRequested, this, &MainWindow::frontPage);
    connect(page8, &Page8::orderRequested, this, &MainWindow::orderRequested);
    connect(page8, &Page8::storeRequested, this, &MainWindow::storeRequested);
    connect(page8, &Page8::productionRequested, this, &MainWindow::productionRequested);
    connect(page8, &Page8::financeRequested, this, &MainWindow::financeRequested);
    connect(page8, &Page8::pageRequested7, this, &MainWindow::pageRequested7);
    connect(page8, &Page8::pageRequested8, this, &MainWindow::pageRequested8);
    connect(page8, &Page8::pageRequested9, this, &MainWindow::pageRequested9);
    connect(page8, &Page8::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page8, &Page8::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page8,&Page8::pageRequested13,this,&MainWindow::pageRequested13);



    connect(page9, &Page9::orderRequested, this, &MainWindow::orderRequested);
    connect(page9, &Page9::storeRequested, this, &MainWindow::storeRequested);
    connect(page9, &Page9::productionRequested, this, &MainWindow::productionRequested);
    connect(page9, &Page9::financeRequested, this, &MainWindow::financeRequested);
    connect(page9, &Page9::pageRequested7, this, &MainWindow::pageRequested7);
    connect(page9, &Page9::pageRequested8, this, &MainWindow::pageRequested8);
    connect(page9, &Page9::pageRequested9, this, &MainWindow::pageRequested9);
    connect(page9, &Page9::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page9, &Page9::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page9,&Page9::pageRequested13,this,&MainWindow::pageRequested13);

    connect(page10, &Page10::orderRequested, this, &MainWindow::orderRequested);
    connect(page10, &Page10::storeRequested, this, &MainWindow::storeRequested);
    connect(page10, &Page10::productionRequested, this, &MainWindow::productionRequested);
    connect(page10, &Page10::financeRequested, this, &MainWindow::financeRequested);

    connect(page10, &Page10::pageRequested11, this, &MainWindow::pageRequested11);
    connect(page10, &Page10::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page10, &Page10::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page10,&Page10::pageRequested13,this,&MainWindow::pageRequested13);

    connect(page11, &Page11::orderRequested, this, &MainWindow::orderRequested);
    connect(page11, &Page11::storeRequested, this, &MainWindow::storeRequested);
    connect(page11, &Page11::productionRequested, this, &MainWindow::productionRequested);
    connect(page11, &Page11::financeRequested, this, &MainWindow::financeRequested);

    connect(page11, &Page11::pageRequested11, this, &MainWindow::pageRequested11);
    connect(page11, &Page11::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page11, &Page11::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page11,&Page11::pageRequested13,this,&MainWindow::pageRequested13);

    connect(page12, &Page12::orderRequested, this, &MainWindow::orderRequested);
    connect(page12, &Page12::storeRequested, this, &MainWindow::storeRequested);
    connect(page12, &Page12::productionRequested, this, &MainWindow::productionRequested);
    connect(page12, &Page12::financeRequested, this, &MainWindow::financeRequested);

    connect(page12, &Page12::pageRequested11, this, &MainWindow::pageRequested11);
    connect(page12, &Page12::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page12, &Page12::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page12,&Page12::pageRequested13,this,&MainWindow::pageRequested13);

    connect(page13, &Page13::orderRequested, this, &MainWindow::orderRequested);
    connect(page13, &Page13::storeRequested, this, &MainWindow::storeRequested);
    connect(page13, &Page13::productionRequested, this, &MainWindow::productionRequested);
    connect(page13, &Page13::financeRequested, this, &MainWindow::financeRequested);
    connect(page13, &Page13::pageRequested10, this, &MainWindow::pageRequested10);
    connect(page13, &Page13::addEmployeeRequested, this, &MainWindow::addEmployeeRequested);
    connect(page13,&Page13::pageRequested13,this,&MainWindow::pageRequested13);



    connect(page1, &Page1::adminLogin, this, [=]() {
        emit updateOrderWidget();
    });
    connect(page1, &Page1::salesLogin, this, [=]() {
        emit sales();
        emit updateOrderWidget();
    });
    connect(page1, &Page1::financeLogin, this, [=]() {
        emit finance();
        emit updateOrderWidget();
    });
    connect(page1, &Page1::warehouseLogin, this, [=]() {
        emit warehouse();
        emit updateOrderWidget();
    });


    connect(this, &MainWindow::warehouse, page2, &Page2::signuphide);
    connect(this, &MainWindow::warehouse, page3, &Page3::signuphide);
    connect(this, &MainWindow::warehouse, page4, &Page4::signuphide);
    connect(this, &MainWindow::warehouse, page5, &Page5::signuphide);
    connect(this, &MainWindow::warehouse, page6, &Page6::signuphide);
    connect(this, &MainWindow::warehouse, page7, &Page7::signuphide);
    connect(this, &MainWindow::warehouse, page8, &Page8::signuphide);
    connect(this, &MainWindow::warehouse, page9, &Page9::signuphide);
    connect(this, &MainWindow::warehouse, page10, &Page10::signuphide);
    connect(this, &MainWindow::warehouse, page11, &Page11::signuphide);
    connect(this, &MainWindow::warehouse, page12, &Page12::signuphide);
    connect(this, &MainWindow::warehouse, page13, &Page13::signuphide);



    connect(this, &MainWindow::sales, page2, &Page2::signuphide);
    connect(this, &MainWindow::sales, page3, &Page3::signuphide);
    connect(this, &MainWindow::sales, page4, &Page4::signuphide);
    connect(this, &MainWindow::sales, page5, &Page5::signuphide);
    connect(this, &MainWindow::sales, page6, &Page6::signuphide);
    connect(this, &MainWindow::sales, page7, &Page7::signuphide);
    connect(this, &MainWindow::sales, page8, &Page8::signuphide);
    connect(this, &MainWindow::sales, page9, &Page9::signuphide);
    connect(this, &MainWindow::sales, page10, &Page10::signuphide);
    connect(this, &MainWindow::sales, page11, &Page11::signuphide);
    connect(this, &MainWindow::sales, page12, &Page12::signuphide);
    connect(this, &MainWindow::sales, page13, &Page13::signuphide);


    connect(this, &MainWindow::finance, page2, &Page2::signuphide);
    connect(this, &MainWindow::finance, page3, &Page3::signuphide);
    connect(this, &MainWindow::finance, page4, &Page4::signuphide);
    connect(this, &MainWindow::finance, page5, &Page5::signuphide);
    connect(this, &MainWindow::finance, page6, &Page6::signuphide);
    connect(this, &MainWindow::finance, page7, &Page7::signuphide);
    connect(this, &MainWindow::finance, page8, &Page8::signuphide);
    connect(this, &MainWindow::finance, page9, &Page9::signuphide);
    connect(this, &MainWindow::finance, page10, &Page10::signuphide);
    connect(this, &MainWindow::finance, page11, &Page11::signuphide);
    connect(this, &MainWindow::finance, page12, &Page12::signuphide);
    connect(this, &MainWindow::finance, page13, &Page13::signuphide);

     connect(page2,&Page2::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page3,&Page3::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page4,&Page4::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page5,&Page5::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page6,&Page6::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page7,&Page7::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page8,&Page8::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page9,&Page9::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page10,&Page10::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page11,&Page11::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page12,&Page12::pageRequested1,this,&MainWindow::pageRequested1);
     connect(page13,&Page13::pageRequested1,this,&MainWindow::pageRequested1);

    connect(this, &MainWindow::warehouse, page2, &Page2::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page2, &Page2::financeHide);//销售权限
    connect(this, &MainWindow::warehouse, page3, &Page3::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page3, &Page3::financeHide);//销售权限

    connect(this, &MainWindow::warehouse, page4, &Page4::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page4, &Page4::financeHide);//销售权限
    connect(this, &MainWindow::warehouse, page5, &Page5::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page5, &Page5::financeHide);//销售权限

    connect(this, &MainWindow::warehouse, page6, &Page6::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page6, &Page6::financeHide);//销售权限
    connect(this, &MainWindow::warehouse, page7, &Page7::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page7, &Page7::financeHide);//销售权限

    connect(this, &MainWindow::warehouse, page8, &Page8::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page8, &Page8::financeHide);//销售权限

    connect(this, &MainWindow::warehouse, page9, &Page9::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page9, &Page9::financeHide);//销售权限

    connect(this, &MainWindow::warehouse, page10, &Page10::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page10, &Page10::financeHide);//销售权限

    connect(this, &MainWindow::warehouse, page11, &Page11::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page11, &Page11::financeHide);//销售权限

    connect(this, &MainWindow::warehouse, page12, &Page12::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page12, &Page12::financeHide);//销售权限

    connect(this, &MainWindow::warehouse, page13, &Page13::financeHide);//仓库管理员权限
    connect(this, &MainWindow::sales, page13, &Page13::financeHide);//销售权限

    connect(this,&MainWindow::updateOrderWidget,page2,&Page2::populateTableWidget);
    connect(this,&MainWindow::LoadingQcharts,page4,&Page4::generateQuarterlyReport);
    connect(this,&MainWindow::initialize,page7,&Page7::initializeInventoryTable);
    connect(this,&MainWindow::updateWidget,page11,&Page11::updateTableWidget);
    connect(this, &MainWindow::LoadingQcharts2, page5, &Page5::generateQuarterlyReport);
    connect(this, &MainWindow::LoadingQcharts3, page3, &Page3::initializeInventoryChart);
    connect(this,&MainWindow::updateConnect,page13,&Page13::generateCurrentDatabaseDataChart);
    connect(this,&MainWindow::updateEmploy,page12,&Page12::initializeEmployeeTable);
//    //打开connection弹窗
//    if (connectionDialog->exec() == QDialog::Accepted) {
//        DatabaseManager &dbManager = DatabaseManager::instance();
//        bool connected = false;

//     if (connectionDialog->localConnectionRadioButton->isChecked()) {
//            QString localDbName = connectionDialog->getLocalDbName();
//            if (dbManager.connectToSqlite(localDbName)) {
//                connected = true;
//            } else {
//                //qDEbug() << "Failed to connect to local database.";
//            }
//        } else if (connectionDialog->remoteConnectionRadioButton->isChecked()) {
//            QString host = connectionDialog->getHost();
//            int port = connectionDialog->getPort().toInt();
//            QString remoteDbName = connectionDialog->getRemoteDbName();
//            QString username = connectionDialog->getUsername();
//            QString password = connectionDialog->getPassword();
//            if (dbManager.connectToMySQL(host, port, remoteDbName, username, password)) {
//                connected = true;
//            } else {
//                //qDEbug() << "Failed to connect to remote database.";
//            }
//        }

//        if (connected) {
//            // ConnectionDialog succeeded, show page1
//            stackedWidget->setCurrentWidget(page1);
//        } else {
//            // Connection failed, reopen the ConnectionDialog
//            connectionDialog->exec();
//        }
//    } else {
//        QApplication::quit();  // Close all windows when the ConnectionDialog is canceled
//    }
}

MainWindow::~MainWindow()
{
    delete stackedWidget;
}

void MainWindow::nextPage()
{
    int currentIndex = stackedWidget->currentIndex();
    if (currentIndex < stackedWidget->count() - 1)
    {
        stackedWidget->setCurrentIndex(currentIndex + 1);
    }
}
void MainWindow::pageRequested1() {
    int pageIndex = 0;
    stackedWidget->setCurrentIndex(pageIndex);
}
void MainWindow::frontPage() {
    int frontIndex = 1;
    stackedWidget->setCurrentIndex(frontIndex);
}

//订单跳转
void MainWindow::orderRequested() {
    int orderIndex = 1;
    stackedWidget->setCurrentIndex(orderIndex);
    emit updateOrderWidget();
}

//添加员工跳转
void MainWindow::addEmployeeRequested() {
    int pageIndex = 11;
    stackedWidget->setCurrentIndex(pageIndex);
    emit updateEmploy();
}

//生产跳转
void MainWindow::productionRequested() {
    int productionIndex = 3;
    stackedWidget->setCurrentIndex(productionIndex);
    emit LoadingQcharts();
}

//仓库跳转
void MainWindow::storeRequested() {
    int storeIndex = 2;
    stackedWidget->setCurrentIndex(storeIndex);
    emit LoadingQcharts3();
}

//财务跳转
void MainWindow::financeRequested() {
    int financeIndex = 4;
    stackedWidget->setCurrentIndex(financeIndex);
    emit LoadingQcharts2(); // 假设订单页面也需要刷新图表
}

void MainWindow::pageRequested6() {
    int pageIndex = 5;
    stackedWidget->setCurrentIndex(pageIndex);
}

void MainWindow::pageRequested7() {
    int pageIndex = 6;
    stackedWidget->setCurrentIndex(pageIndex);
    emit initialize();
}

void MainWindow::pageRequested8() {
    int pageIndex = 7;
    stackedWidget->setCurrentIndex(pageIndex);
}

void MainWindow::pageRequested9() {
    int pageIndex = 8;
    stackedWidget->setCurrentIndex(pageIndex);
}

void MainWindow::pageRequested10() {
    int pageIndex = 9;
    stackedWidget->setCurrentIndex(pageIndex);
}

void MainWindow::pageRequested11() {
    int pageIndex = 10;
    stackedWidget->setCurrentIndex(pageIndex);
    emit updateWidget();
}

void MainWindow::pageRequested13() {
    int pageIndex = 12;
    stackedWidget->setCurrentIndex(pageIndex);
    emit updateConnect();
}

void MainWindow::onWarehouseLogin() {
    emit warehouse();
}

void MainWindow::onSalesLogin() {
    emit sales();
}



void MainWindow::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        m_dragging = true;
        m_dragPosition = event->globalPos() - frameGeometry().topLeft();
        event->accept();
    }
}

void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
    if (m_dragging && (event->buttons() & Qt::LeftButton)) {
        move(event->globalPos() - m_dragPosition);
        event->accept();
    }
}

void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
    m_dragging = false;
}

void MainWindow::on_minimizeButton_clicked()
{
    showMinimized();
}

void MainWindow::on_maximizeButton_clicked()
{
    if (isMaximized())
        showNormal();
    else
        showMaximized();
}

void MainWindow::on_closeButton_clicked()
{
    close();
}

